#include "Plane.hpp"
#include "Vec3.hpp"

namespace Intersector
{
   inline bool RayPlane(Vec3  aOrigin,
                        Vec3  aRay,
                        Plane aPlane,
                        Vec3& aHitPoint)
   {
      const Vec3& n = aPlane.normal;
      const Vec3& p = aPlane.point;
      const Vec3& v = aRay;
      const Vec3& o = aOrigin;
      float num = (p.x - o.x) * n.x + (p.y - o.y) * n.y + (p.z - o.z) * n.z;
      float den = n.x * v.x + n.y * v.y + n.z * v.z;
      float t = num / den;
      if (t < 0) return false;
      aHitPoint = o + v * t;
      return true;
   }

}